/**
 * 后置处理器
 * 
 */
class PostProcessor {

    /**
     * JSON提取器
     * 
     * @param {XMLBuilder} parent 
     * @param {{ testname: String, variableName: String, jsonPath: String }} config 
     */
    createJsonExtractor(parent, config = { testname: "JSON Extractor", variableName: "", jsonPath: "" }) {
        const { testname, variableName, jsonPath } = config;
        const jmxJsonExtractor = parent.ele("JSONPostProcessor", { guiclass: "JSONPostProcessorGui", testclass: "JSONPostProcessor", testname: testname });
        jmxJsonExtractor.ele("stringProp", { name: "JSONPostProcessor.referenceNames" }).txt(variableName).up()
            .ele("stringProp", { name: "JSONPostProcessor.jsonPathExprs" }).txt(jsonPath).up()
            .ele("stringProp", { name: "JSONPostProcessor.match_numbers" }).txt("0")
        jmxJsonExtractor.up().ele("hashTree");
    }

    /**
     * JSR223 后置处理程序
     * 
     * @param {XMLBuilder} parent 
     * @param {{ testname: String, comments: String, script: String }} config 
     * @returns 
     */
    createJsr223PostProcessor(parent, config = { testname: "JSR223 PostProcessor", comments: "", script: "" }) {
        const { testname, comments, script } = config;
        const jmxJsr223PostProcessor = parent.ele("JSR223PostProcessor", { guiclass: "TestBeanGUI", testclass: "JSR223PostProcessor", testname: testname });
        jmxJsr223PostProcessor.ele("stringProp", { name: "scriptLanguage" }).txt("groovy").up()
            .ele("stringProp", { name: "parameters" }).txt("").up()
            .ele("stringProp", { name: "filename" }).txt("").up()
            .ele("stringProp", { name: "cacheKey" }).txt("true").up()
            .ele("stringProp", { name: "script" }).txt(script).up()
            .ele("stringProp", { name: "TestPlan.comments" }).txt(comments);
        jmxJsr223PostProcessor.up().ele("hashTree");
    }

}

module.exports = PostProcessor;

